use std::collections::HashMap;
use std::fmt::Debug;

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)] // <-- this is a container attribute
#[serde(rename_all = "snake_case")]
pub struct Config {
    pub server: Server,
    pub database: HashMap<String, DataBase>,
    pub visible: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Server {
    #[serde(rename = "id")]
    pub id: i8,
    #[serde(rename(serialize = "name", deserialize = "name"))]
    pub name: String,
}

pub trait DataBaseDsn {
    fn to_dsn(&self) -> String {
        println!("to_dsn!");
        String::from("to_dsn")
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct DataBase {
    pub host: String,
    pub username: String,
    pub password: String,
    pub database: String,
}

impl DataBase {
    pub fn to_dsn(&self) -> String {
        return String::from("DataBaseDsn");
    }
}

impl DataBaseDsn for DataBase {
    fn to_dsn(&self) -> String {
        return String::from("DataBaseDsn");
    }
}
